feat(recalibration): a temperature per predicted label, when one temperature is the wrong shape - #103
Merged
Merged
Conversation
…erature is the wrong shape One temperature cannot reach a model that is overconfident on one label and honest on the rest, and the global verdict already diagnosed that and stopped. Now, after exactly the two wrong-shape verdicts, the report fits one temperature per predicted label on the same split and judges it by the same rule; a label with under 100 fit rows is left as it came and named. Its block says the temperatures are not comparable with the global one and names which correction to apply. scripts/per_label_study.py measures it on the mock: from about 100 fit rows per label it lands a per-label bias inside the floor where one temperature leaves 1.2 to 3.3 times it, and where one temperature is the right shape the extra parameters cost 5 to 15 percent more held-out ECE. The global verdict's properties move to a shared _Gate, so both fits earn their verdict by one rule. Fixes #4. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4. This follows the approved design.
What it does
When it runs. Only after the global fit ends in one of the two wrong-shape verdicts:
no_material_improvement(refused) orresidual_above_floor(partial). The global path is unchanged and always runs first. When the model is already calibrated or the interval spans 1.0, the fallback never runs.The method.
recalibrate_per_label()fits one temperature per predicted label:predicted_labels, not an argmax, since the two differ on a tie.The verdict. The global result's verdict logic moves to a shared
_Gate, so both fits reach recommended, partial or refused by exactly the same rule.Row gate. A label with fewer than 100 fit rows (
DEFAULT_MIN_LABEL_ROWS) is left as it came, and the report names it with its counts.The report
A
#### Per-label fallbackblock under Recalibration, in a real render:The global fit on that same run was partial, at 1.6 times the floor.
A refusal prints row counts only, no temperatures and no ECE, following the existing rule that a refused fit shows no number anyone could lift. The Apply line picks per-label if it isn't refused and leaves less behind, or when the global fit was refused. Otherwise it picks the partial global temperature, and otherwise neither.
Evidence
scripts/per_label_study.pyruns the mock at 5 seeds. Each figure is held-out ECE over the floor's 95th percentile:Also
label_descriptions" item is now marked landed in v0.1.1 (label_descriptions are parsed and then dropped #39).Tests:
tests/test_per_label_recalibration.py, 7 tests covering recovery against the global fit, which labels get corrected, the identical split, the row gate, the honest-model refusal, and the report block appearing (and not appearing). The full suite is 606 passed.docs/example-report.mdis unchanged. The gate, the site checks and the prose checks all pass.🤖 Generated with Claude Code